<!-- eslint-disable prettier/prettier -->
<!-- eslint-disable @typescript-eslint/explicit-function-return-type -->
<script lang="ts" setup>
import { ref } from 'vue'
import { useUserStore } from '@renderer/store/user'
import { storeToRefs } from 'pinia'
import { test } from '@renderer/api/test'

// store对象
const userStore = useUserStore()

// 获取store暴露数据
const { count } = storeToRefs(userStore)

// 请求数据
const testData = ref<string>('')

// 测试发送到主线程
const ipcHandle = (): void => window.electron.ipcRenderer.send('ping')

// 打开新窗口
const open = (): void =>
  window.electron.ipcRenderer.send('open-window', {
    path: '/list',
    width: 800,
    height: 640
})

// 加
const jiaCount = () => {
  userStore.count += 1
}

// 减
const jianCount = () => {
  userStore.count -= 1
}

// 获取接口数据
const testApi = async () => {
  let getData = {
    id: 5,
    size: 10,
    page: 1
  }
  let { data } = await test(getData)
  testData.value = JSON.stringify(data)
}

</script>

<template>
  <div>
    <div>count: {{ count }}</div>
    <el-button type="primary" size="default" @click="ipcHandle">请求主进程</el-button>
    <el-button type="primary" size="default" @click="jiaCount">加1</el-button>
    <el-button type="primary" size="default" @click="jianCount">减1</el-button>
    <el-button type="primary" size="default" @click="testApi">请求数据</el-button>
    <el-button type="primary" size="default" @click="open">打开列表</el-button>
    <div>
      {{ testData }}
    </div>
  </div>
</template>
